//
//  WDVehicleProcessConditionView.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/10.
//

#import "WDVehicleProcessConditionView.h"
#import "WDWorderOrderMaintenanceVehicleViewModel.h"
#import "TYZImageTitleButton.h"

@interface WDVehicleProcessConditionView ()
@property (nonatomic, strong) WDWorderOrderMaintenanceVehicleViewModel *viewModel;

@property (nonatomic, strong) UILabel *titleLabel;

/// 继续维修
@property (nonatomic, strong) TYZImageTitleButton *btnContine;

/// 维修完成
@property (nonatomic, strong) TYZImageTitleButton *btnFinish;

@end

@implementation WDVehicleProcessConditionView

- (void)initWithVar {
    [super initWithVar];
    
}

- (void)initWithSubView {
    [super initWithSubView];
    
    [self initWithTitleLabel];
    
//    self.backgroundColor = [UIColor orangeColor];
}

- (void)initWithTitleLabel {
    if (!_titleLabel) {
        CGRect frame = CGRectMake(20, 15, self.width - 40, 18);
        _titleLabel = [UILabel createWithLabel:self frame:frame font:[UIFont systemFontOfSize:14 weight:UIFontWeightMedium] propertiesBlock:^(UILabel * _Nonnull label) {
            label.text = @"本次处理后车辆状况";
        }];
        _titleLabel.attributedText = [EDSUtility attributeTitle:@"本次处理后车辆状况 " titleColor:[UIColor colorWithHexString:@"#000000"] titleFont:[UIFont systemFontOfSize:14 weight:UIFontWeightRegular] value:@"*" valueColor:[UIColor colorWithHexString:@"#F24C55"] valueFont:[UIFont systemFontOfSize:14 weight:UIFontWeightRegular]];
    }
}

- (void)initWithBtnContine {
    if (!_btnContine) {
        UIImage *imageNor = [UIImage imageNamed:@"ic_ads_check_nor_blue"];
        UIImage *imageSel = [UIImage imageNamed:@"ic_ads_check_sel_blue"];
        TYZCommonCellModel *model = [self.viewModel.processConditions objectAtIndex:0];
        UIFont *font = [UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
        float width = [model.title widthForFont:font] + 5 + imageNor.size.width;
        CGRect frame = CGRectMake(20, self.titleLabel.bottom + 15, width, 24);
        _btnContine = [TYZImageTitleButton createWithImageButton:self frame:frame font:font target:self action:@selector(actionWithProcess:) propertiesBlock:^(TYZImageTitleButton * _Nonnull button) {
            [button setTitle:model.title forState:UIControlStateNormal];
            [button setTitleColor:[UIColor colorWithHexString:@"#000000"] forState:UIControlStateNormal];
            [button setImage:imageNor forState:UIControlStateNormal];
            [button setImage:imageSel forState:UIControlStateSelected];
            [button layoutButtonWithEdgeInsetsStyle:TYZButtonEdgeInsetsStyleLeft imageTitleSpace:4];
        }];
        [self.viewList addObject:_btnContine];
    }
}

- (void)initWithBtnFinish {
    if (!_btnFinish) {
        UIImage *imageNor = [UIImage imageNamed:@"ic_ads_check_nor_blue"];
        UIImage *imageSel = [UIImage imageNamed:@"ic_ads_check_sel_blue"];
        TYZCommonCellModel *model = [self.viewModel.processConditions objectAtIndex:1];
        UIFont *font = [UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
        float width = [model.title widthForFont:font] + 5 + imageNor.size.width;
        CGRect frame = CGRectMake(self.width * 0.5, self.titleLabel.bottom + 15, width, 24);
        _btnFinish = [TYZImageTitleButton createWithImageButton:self frame:frame font:font target:self action:@selector(actionWithProcess:) propertiesBlock:^(TYZImageTitleButton * _Nonnull button) {
            [button setTitle:model.title forState:UIControlStateNormal];
            [button setTitleColor:[UIColor colorWithHexString:@"#000000"] forState:UIControlStateNormal];
            [button setImage:imageNor forState:UIControlStateNormal];
            [button setImage:imageSel forState:UIControlStateSelected];
            [button layoutButtonWithEdgeInsetsStyle:TYZButtonEdgeInsetsStyleLeft imageTitleSpace:4];
        }];
        [self.viewList addObject:_btnFinish];
    }
}

- (void)actionWithProcess:(id)sender {
    UIButton *btn = (UIButton *)sender;
    TYZCommonCellModel *curModel = nil;
    for (int i=0; i<self.viewList.count; i++) {
        TYZCommonCellModel *model = self.viewModel.processConditions[i];
        UIButton *button = self.viewList[i];
        if (button == btn) {
            curModel = model;
            button.selected = !button.selected;
        } else {
            button.selected = NO;
        }
        model.isCheck = button.selected;
    }
    if (self.viewBlock) {
        self.viewBlock(curModel);
    }
}


- (void)updateWithViewData:(id)data {
    self.viewModel = data;
    
    [self initWithBtnContine];
    
    [self initWithBtnFinish];
}

@end
